/*
 * Copyright 2018 JessYan
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lianxian.xindong.mvp.ui.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.hxb.library.base.BaseActivity;
import com.hxb.library.di.component.AppComponent;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;

import com.lianxian.xindong.R;
import com.lianxian.xindong.commonres.utils.UserUitls;
import com.lianxian.xindong.commonsdk.core.RouterHub;

/**
 * @作者： HeXingBo
 * @描述：
 */
@Route(path = RouterHub.APP_SPLASHACTIVITY)
public class SplashActivity extends BaseActivity {

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {

    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_splash;
    }

    @SuppressLint("CheckResult")
    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        Observable.timer(3, TimeUnit.SECONDS)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<Long>() {
                    @Override
                    public void accept(Long aLong) throws Exception {
                        startActivity();
                    }
                });
    }

    private void startActivity() {
        if (UserUitls.isLogin(false, false)) {
                ARouter.getInstance()
                        .build(RouterHub.APP_MAINACTIVITY)
                        .navigation(SplashActivity.this);
        } else {
            ARouter.getInstance()
                    .build(RouterHub.LOGIN_LOGINPHONEACTIVITY)
                    .navigation(SplashActivity.this);
        }
        finish();
    }

}
